package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

public class AnnotationConsumerMain {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        // 获取消费者组件
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        while (true) {
            /*System.in.read();
            String hello = service.sayHello("world", 0);
            System.out.println("result: " + hello);*/
            for (int i = 0; i < 1000; i++) {
                Thread.sleep(6);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String msg = service.sayHello("world", 0);
                        System.out.println(msg);
                    }
                }).start();
            }
        }
    }

    /**
     * 配置类
     */
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
